#pragma once

#include "ISelection.h"

class Selection : public ISelection
{
public:
	Selection(){}
	virtual ~Selection(){}

	BEGIN_DEFINE_CLASS(CLSID_Selection)
		DEFINE_INTERFACE_ENTRY(ISelection)
	END_DEFINE_CLASS()

	virtual void SelectOne(IObject* object)
	{
		m_selObjects.clear();
		m_selObjects.push_back(object);
	}

	virtual void SelectMore(const objectarray& objects)
	{
		m_selObjects.clear();

		objectarray::const_iterator itbegin = m_selObjects.begin();
		objectarray::const_iterator itend = m_selObjects.end();
		for (; itbegin != itend; ++itbegin)
			m_selObjects.push_back(*itbegin);
	}

	virtual void DeselectOne(IObject* object)
	{
		objectarray::iterator itfind = std::find(m_selObjects.begin(),m_selObjects.end(),object);
		if (itfind != m_selObjects.end())
			m_selObjects.erase(itfind);
	}

	virtual void DeSelectAll()
	{
		m_selObjects.clear();
	}

	virtual uint32 GetSelected(objectarray& objects) const
	{
		objectarray::const_iterator itbegin = m_selObjects.begin();
		objectarray::const_iterator itend = m_selObjects.end();
		for (; itbegin != itend; ++itbegin)
			objects.push_back(*itbegin);

		return objects.size();
	}

	virtual uint32 CountSelected() const
	{
		return m_selObjects.size();
	}
	
	virtual IObject* GetSelected(uint32 index)
	{
		ASSERT(index < CountSelected());
		if (index < m_selObjects.size())
			return m_selObjects[index];
		return NULL;
	}

private:
	objectarray m_selObjects;
};